import moment from 'moment'
export function formatDateTime({ cellValue }) {
  return cellValue === undefined || cellValue === null
    ? ''
    : moment(new Date(cellValue)).format('yyyy-MM-DD hh:mm')
}

export function formatDate({ cellValue }) {
  return moment(cellValue).format('yyyy-MM-DD')
}

export function formatSex({ cellValue }) {
  var res = ''
  switch (cellValue) {
    case 1:
      res = '男'
      break
    case 2:
      res = '女'
      break
    default:
      res = '未知'
      break
  }
  return res
}

export function phoneCheck(rule, value, callbackFn) {
  const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
  if (!reg.test(value)) {
    callbackFn('请输入正确的手机号码')
    return
  }
  callbackFn()
}
export function moneyCheck(rule, value, callbackFn) {
  const reg = /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/
  console.log('value', value)
  if (!reg.test(value)) {
    callbackFn('请输入正确金额，只允许两位小数')
    return
  }
  callbackFn()
}

// 时间选择限制
export function disabledDate(current) {
  return current && current <= moment().endOf('day')
}
